var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    listname: -1,
    weaponlist: [],
    menutype: ['攻击类型排序', '槽位排序'],
    index: "0",
    weaponlistV2: [
      {
        title: '近程动能武器',
        detail: [
          {
            title: 'Gust(小喷)',
            id: 'Gust'
          }, {
            title: 'Storm(中喷)',
            id: 'Storm'
          }, {
            title: 'Thunder(重喷)',
            id: 'Thunder'
          },
          {
            title: 'Punisher(500米轻机枪)',
            id: 'Punisher'
          },
          {
            title: 'Punisher T(500米机枪)',
            id: 'PunisherT'
          },
          {
            title: 'Avenger(重机枪)',
            id: 'Avenger'
          },
          {
            title: 'Sting(小毒枪)',
            id: 'Sting'
          },
          {
            title: 'Wasp(中毒枪)',
            id: 'Wasp'
          }
        ]
      },
      {
        title: '远程动能武器',
        detail: [
          {
            title: 'Molot(800米轻机枪)',
            id: 'Molot'
          },
          {
            title: 'Molot T(800米轻机枪)',
            id: 'MolotT'
          },
          {
            title: 'Tempest(舰炮)',
            id: 'Tempest'
          },
          {
            title: 'Kang Dae(方口炮)',
            id: 'KangDae'
          }, {
            title: 'Nashorn(圆口炮)',
            id: 'Nashorn'
          }
        ]
      },
      {
        title: '近程能量武器',
        detail: [
          {
            title: 'Magnum(绿豆)',
            id: 'Magnum'
          },
          {
            title: 'Taran(豌豆)',
            id: 'Taran'
          },
          {
            title: 'Redeemer(大豆)',
            id: 'Redeemer'
          },
          {
            title: 'Blaze(小火枪)',
            id: 'Blaze'
          }, {
            title: 'Igniter(中火枪)',
            id: 'Igniter'
          },
          {
            title: 'Ember(大火枪)',
            id: 'Ember'
          },
          {
            title: 'Halo(小定喷)',
            id: 'Halo'
          },
          {
            title: 'Corona(中定喷)',
            id: 'Corona'
          },
          {
            title: 'Glory(大定喷)',
            id: 'Glory'
          },
          {
            title: 'Shredder(小定枪)',
            id: 'Shredder'
          }
        ]
      },
      {
        title: '中程能量武器',
        detail: [
          {
            title: 'Viper(大毒枪)',
            id: 'Viper'
          },
          {
            title: 'Shocktrain(光棱)',
            id: 'Shocktrain'
          },
          {
            title: 'Pulsar(中定枪)',
            id: 'Pulsar'
          },
          {
            title: 'Spark(小电枪)',
            id: 'Spark'
          }, {
            title: 'Scourge(中电枪)',
            id: 'Scourge'
          },
          {
            title: 'Calamity(大电枪)',
            id: 'Calamity'
          },
          {
            title: 'Ion(中宙斯)',
            id: 'Ion'
          },
          {
            title: 'Zeus(宙斯)',
            id: 'Zeus'
          }
        ]
      },
      {
        title: '远程能量武器',
        detail: [
          {
            title: 'Marquess(小龙炮)',
            id: 'Marquess'
          },
          {
            title: 'Hussar(中龙炮)',
            id: 'Hussar'
          },
          {
            title: 'Dragoon(龙炮)',
            id: 'Dragoon'
          },
          {
            title: 'Arbalest(小聚能)',
            id: 'Arbalest'
          }, {
            title: 'Ballista(中聚能)',
            id: 'Ballista'
          },
          {
            title: 'Trebuchet(大聚能)',
            id: 'Trebuchet'
          },
          {
            title: 'Gekko(小激光)',
            id: 'Gekko'
          },
          {
            title: 'Flux(大激光)',
            id: 'Flux'
          }
        ]
      },
      {
        title: '非制导火箭武器',
        detail: [
          {
            title: 'Pinata(红炸)',
            id: 'Pinata'
          },
          {
            title: 'Orkan(黄炸)',
            id: 'Orkan'
          }, {
            title: 'Exodus(黑炸)',
            id: 'Exodus'
          },
          {
            title: 'Pin(轻500炸)',
            id: 'Pin'
          },
          {
            title: 'Tulumbas(500炸)',
            id: 'Tulumbas'
          }, {
            title: 'Avalanche(重500炸)',
            id: 'Avalanche'
          },
          {
            title: 'Trident(三叉戟)',
            id: 'Trident'
          },
          {
            title: 'Noricum(烟花)',
            id: 'Noricum'
          },
          {
            title: 'Zenit(礼花)',
            id: 'Zenit'
          }
        ]
      },
      {
        title: '制导导弹武器',
        detail: [
          {
            title: 'Aphid(小火圈)',
            id: 'Aphid'
          },
          {
            title: 'Vortex(中火圈)',
            id: 'Vortex'
          }, {
            title: 'Thermite(大火圈)',
            id: 'Thermite'
          },
          {
            title: 'Spiral(小导弹)',
            id: 'Spiral'
          },
          {
            title: 'Hydra(九头蛇)',
            id: 'Hydra'
          }, {
            title: 'Chimera(奇美拉)',
            id: 'Chimera'
          }
        ]
      }
    ],
    weaponlist_def: [
      {
        title: '防御系统',
        detail: [
          {
            title: 'Ancile(重能量盾)',
            id: 'Ancile'
          },
          {
            title: 'Ecu(盾)',
            id: 'Ecu'
          }
        ]
      }
    ]
  },

  onShow: function () {
    var that = this;
    this.changemenutype('0')
  },

  //自定义过去菜单类型
  changemenutype(type) {
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration: 10000
    })
    const db = wx.cloud.database()
    // 查询当前用户所有的 counters
    try {
      db.collection('menulist').where({
        id: 'weaponlist',
        type: type
      }).get({
        success: res => {
          var detailobj = res.data[0];
          var dataobj = JSON.parse(detailobj.data)
          this.setData({
            weaponlist: dataobj
          })
          wx.hideToast();
        },
        fail: err => {
          wx.showToast({
            icon: 'none',
            title: '查询菜单失败，请检查网络'
          })
          wx.hideToast();
        }
      })
    } catch (e) {
      wx.showToast({
        title: '读取数据失败，请检查网络',
        icon: 'none',
        duration: 10000
      })
    }
  },

  //自定义方法
  listactive: function (e) {
    this.setData({ listname: e.currentTarget.dataset.listname })
  },
  weaponrouter: function (e) {
    wx.navigateTo({
      router: 'weapon',
      url: '/pages/Wweapon_detail/Wweapon_detail' + '?id=' + e.currentTarget.id
    })
  },
  bindPickerChange(e) {
 
    this.setData({
      index: e.detail.value
    })
    this.changemenutype(e.detail.value)
  },
  weaponrouter_v2: function (e) {
    wx.navigateTo({
      router: 'weapon',
      url: '/pages/Wweapon_detail_v2/Wweapon_detail' + '?id=' + e.currentTarget.id
    })
  },
  weaponrouter_def: function (e) {
 
    wx.navigateTo({
      router: 'weapon',
      url: '/pages/Wweapon_detail_defense/Wweapon_detail_defense' + '?id=' + e.currentTarget.id
    })
  }
})